package com.zhl.dao;

import com.zhl.dao.dasedao.BaseDao;
import com.zhl.model.Userfocus;
import com.zhl.utils.JdbcUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserfocusDao extends BaseDao {

    JdbcTemplate jdbcTemplate = new JdbcTemplate(JdbcUtils.getDataSource());

    public UserfocusDao() {
        super(Userfocus.class);
    }

    public Userfocus findUserfocusById(Integer MyId,Integer uId){
        Userfocus userfocus = null;
        String sql = "select * from userfocus where user_id = ? and user_focus_id = ?";
        try {
            userfocus = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Userfocus.class), MyId, uId);
        }catch (Exception e){
            return null;
        }
        return userfocus;
    }

    public boolean deleteUserfocus(Integer MyId,Integer uId){
        int set = 0;
        String sql = "delete from userfocus where user_id = ? and user_focus_id = ?";
        try {
            set = jdbcTemplate.update(sql,MyId,uId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return set > 0;
    }

}
